package com.westcom.vulb.logic;

import java.util.ArrayList;
import java.util.HashMap;

import android.os.AsyncTask;

import com.westcom.vulb.bean.Card;
import com.westcom.vulb.protocal.http.Request;
import com.westcom.vulb.protocal.http.Response;

public class CardDetail extends BasicLogic 
{
    public static ArrayList<HashMap<String, Object>> getComment(int cardId) 
    {
        return getComment(String.valueOf(cardId));
    }
    
    public static ArrayList<HashMap<String, Object>> getComment(String cardId) 
    {
        ArrayList<String> cardIds = new ArrayList<String>();
        cardIds.add(cardId);
        HashMap<String, Object> comments = getComments(cardIds);
        
        ArrayList<HashMap<String, Object>> commentList = new ArrayList<HashMap<String,Object>>();
        if (comments.get(cardId) != null) 
        {
            commentList = (ArrayList<HashMap<String, Object>>) comments.get(cardId);
        }
        return commentList;
    }
    
    public static HashMap<String, Object> getComments(ArrayList<String> cardIds) 
    {
        HashMap<String, Object> params = new HashMap<String, Object>();
        ArrayList cards = new ArrayList<HashMap<String, Object>>();
        for (String cardId : cardIds) 
        {
            HashMap<String, Object> cardParam = new HashMap<String, Object>();
            cardParam.put("cardId", cardId);
            cardParam.put("start", 0);
            cardParam.put("count", 500);
            cards.add(cardParam);
        }
        params.put("cards", cards);
        
        HashMap<String, Object> responseData = BasicLogic.request(Request.URL_CARD_COMMENT_LIST, params);
        
        HashMap<String, Object> comments = new HashMap<String, Object>();
        
        if (responseData != null && responseData.get("cards") != null)
        {
            comments = (HashMap<String, Object>) responseData.get("cards");
        }
        
        return comments;
    }
  
    public static Card getDetail(int cardId) 
    {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("cardId", cardId);
        
        HashMap<String, Object> responseData = BasicLogic.request(Request.URL_CARD_DETAIL, params);
        
        Card card = null;
        if (responseData.get("contents") != null) 
        {
            card = Card.parse(cardId,(String) responseData.get("contents"));
            card.commentCount = Integer.valueOf((String) responseData.get("commentCount").toString());
            card.goodCount = Integer.valueOf((String) responseData.get("good").toString());
        } else 
        {
            card = new Card(cardId);
        }
        return card;
    }
}